package com.ruoyi.web.controller.market.source;

import java.util.List;
import java.util.Map;

import com.ruoyi.source.service.ISourceBaseInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.SourceRecordInfo;
import com.ruoyi.source.service.ISourceRecordInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.SourceRecordInfoWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据来源记录Controller
 * 
 * @author ruoyi
 * @date 2023-05-26
 */
@Controller
@RequestMapping("/source/info")
public class SourceRecordInfoController extends BaseController
{
    private String prefix = "source/info";

    @Autowired
    private ISourceRecordInfoService sourceRecordInfoService;
    @Autowired
    private ISourceBaseInfoService sourceBaseInfoService;

    @RequiresPermissions("source:info:view")
    @GetMapping()
    public String info(ModelMap mmap)
    {
        List<Map<String, Object>> dataList = sourceBaseInfoService.selectSimpleDataList();
        mmap.put("dataList", dataList);

        return prefix + "/info";
    }

    /**
     * 查询数据来源记录列表
     */
    @RequiresPermissions("source:info:view")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SourceRecordInfo sourceRecordInfo)
    {
        startPage();
        List<Map<String, Object>> mapList = sourceRecordInfoService.selectSourceRecordInfoListMap(sourceRecordInfo);
        mapList = new SourceRecordInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出数据来源记录列表
     */
    @RequiresPermissions("source:info:export")
    @Log(title = "数据来源记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SourceRecordInfo sourceRecordInfo)
    {
        List<SourceRecordInfo> list = sourceRecordInfoService.selectSourceRecordInfoList(sourceRecordInfo);
        ExcelUtil<SourceRecordInfo> util = new ExcelUtil<SourceRecordInfo>(SourceRecordInfo.class);
        return util.exportExcel(list, "数据来源记录数据");
    }

    /**
     * 新增数据来源记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数据来源记录
     */
    @RequiresPermissions("source:info:add")
    @Log(title = "数据来源记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SourceRecordInfo sourceRecordInfo)
    {
        return toAjax(sourceRecordInfoService.insertSourceRecordInfo(sourceRecordInfo));
    }

    /**
     * 修改数据来源记录
     */
    @RequiresPermissions("source:info:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SourceRecordInfo sourceRecordInfo = sourceRecordInfoService.selectSourceRecordInfoById(id);
        mmap.put("sourceRecordInfo", sourceRecordInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据来源记录
     */
    @RequiresPermissions("source:info:edit")
    @Log(title = "数据来源记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SourceRecordInfo sourceRecordInfo)
    {
        return toAjax(sourceRecordInfoService.updateSourceRecordInfo(sourceRecordInfo));
    }

    /**
     * 删除数据来源记录
     */
    @RequiresPermissions("source:info:remove")
    @Log(title = "数据来源记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sourceRecordInfoService.deleteSourceRecordInfoByIds(ids));
    }
}
